"""
装饰器不仅可以使用函数形式，也可以使用类型
"""


# 不带参数的装饰器
class Decorator:
    def __init__(self, func):
        self.func = func

    def __call__(self, *args, **kwargs):
        print("Decorator before")
        res = self.func(*args, **kwargs)
        print("Decorator after")
        return res


# 带参数的装饰器
class Decorator2:
    def __init__(self, info):
        self.info = info

    def __call__(self, func):
        def wrapper(*args, **kwargs):
            print("Decorator2 before info :" + self.info)
            res = func(*args, **kwargs)
            print("Decorator2 after")
            return res
        return wrapper


# @Decorator
@Decorator2("information")
def func(n):
    print("func running")
    count = 0
    for i in range(n):
        if i % 2 == 0:
            count += 1
    return count


if __name__ == "__main__":
    print(func(10))
